const mongoose = require('mongoose');

const tourSchema = new mongoose.Schema({
  title: {
    type: String,
    required: true,
    trim: true
  },
  subtitle: {
    type: String,
    default: ''
  },
  price: {
    type: Number,
    required: true,
    min: 0
  },
  originalPrice: {
    type: Number,
    default: null
  },
  image: {
    type: String,
    required: true
  },
  category: {
    type: String,
    required: true,
    enum: ['一日游', '多日游', '当地游', '自由行', '跟团游', '攻略群']
  },
  destination: {
    type: String,
    required: true
  },
  duration: {
    type: String,
    required: true
  },
  description: {
    type: String,
    required: true
  },
  highlights: [String],
  includes: [String],
  excludes: [String],
  rating: {
    type: Number,
    default: 4.5,
    min: 0,
    max: 5
  },
  reviewCount: {
    type: Number,
    default: 0
  },
  soldCount: {
    type: Number,
    default: 0
  },
  tags: [String],
  isHot: {
    type: Boolean,
    default: false
  },
  isAvailable: {
    type: Boolean,
    default: true
  },
  coordinates: {
    lat: Number,
    lng: Number
  },
  
  // 订单相关属性
  allowBooking: {
    type: Boolean,
    default: true
  },
  maxGroupSize: {
    type: Number,
    default: 999 // 最大团队人数，攻略群类型可设置较小值
  },
  minAdvanceBooking: {
    type: Number,
    default: 1 // 最少提前预订天数
  },
  cancellationPolicy: {
    type: String,
    default: '出发前24小时免费取消'
  },
  
  // 供应商信息
  provider: {
    type: String,
    default: '官方自营'
  },
  
  // 预订统计
  totalBookings: {
    type: Number,
    default: 0
  },
  currentMonthBookings: {
    type: Number,
    default: 0
  }
}, {
  timestamps: true
});

// 添加索引
tourSchema.index({ category: 1, destination: 1 });
tourSchema.index({ price: 1 });
tourSchema.index({ isHot: -1, soldCount: -1 });

module.exports = mongoose.model('Tour', tourSchema); 